<template>
    <div v-loading="pageLoading" element-loading-background="rgba(255, 255, 255, 0.7)">
        <cardComponent id="arrearsQueryBox" pageTitle="查询服务类-欠款查询">
            <template slot="cardBody">
                <div class="arrearsQueryMain">
                    <!-- 搜索表单模块 -->
                    <el-form
                        class="searchForm"
                        ref="searchForm"
                        :model="searchForm"
                        :inline="true"
                        label-position="right"
                        size="small"
                        label-width="120px"
                    >
                        <el-row>
                            <el-form-item label="账户类别:" class="text_fl">
                                <el-select
                                    v-model="searchForm.accttype"
                                    placeholder="请选择账户类别"
                                    clearable
                                    @change="changeCardList"
                                >
                                    <el-option
                                        v-for="item in AccountionTYPE_INFO"
                                        :label="item.label"
                                        :value="item.code"
                                        :key="item.label"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="卡号:" class="text_fl">
                                <el-select
                                    v-model="searchForm.cardno"
                                    placeholder="请选择卡号"
                                    clearable
                                    disabled
                                >
                                    <el-option
                                        v-for="item in cardList"
                                        :label="item.CARDNBR"
                                        :value="item.CARDNBR"
                                        :key="item.CARDNBR"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-row>
                    </el-form>
                    <div class="box-group businessIndex">
                        <div class="content">
                            <el-row>
                                <el-col :span="10">
                                    <p>
                                        <span>账面余额:</span>
                                        {{arrearsQuery3001Form.BALNCEFLG=== '+' ?arrearsQuery3001Form.BALNCE:arrearsQuery3001Form.BALNCEFLG + arrearsQuery3001Form.BALNCE}}
                                    </p>
                                    <p>
                                        <span>转账分期未摊销总额(本金+手续费):</span>
                                        {{unpaympamttotal3077}}
                                    </p>
                                    <p>
                                        <span>最近一次还款日期:</span>
                                        {{arrearsQuery3001Form.LASTPAYDAY | formatDate}}
                                    </p>
                                </el-col>
                                <el-col :span="6">
                                    <p>
                                        <span>应收未收违约金:</span>
                                        {{arrearsQuery3001Form.PENCHG}}
                                    </p>
                                    <p>
                                        <span></span>
                                    </p>
                                    <p>
                                        <span>最近一次还款金额:</span>
                                        {{arrearsQuery3001Form.LASTPAYAMT}}
                                    </p>
                                </el-col>
                                <el-col :span="8">
                                    <p>
                                        <span>授权未请款金额:</span>
                                        {{arrearsQuery3001Form.AUTHAMT}}
                                    </p>

                                    <p>
                                        <span>按日分期未摊销本金:</span>
                                        {{unpaympamttotal3121}}
                                    </p>
                                </el-col>
                            </el-row>
                        </div>
                    </div>
                    <div class="box-group businessIndex">
                        <div class="content">
                            <el-row>
                                <el-col :span="8">
                                    <p>
                                        <span>最近一次账单日期:</span>
                                        {{arrearsQuery3001Form.STMTDTE | formatDate}}
                                    </p>
                                </el-col>
                                <el-col :span="8">
                                    <p>
                                        <span>最后还款日:</span>
                                        {{arrearsQuery3001Form.DUEDATE | formatDate}}
                                    </p>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="24">
                                    <p>
                                        <span style="width:18%">最近一期账单未还金额:</span>
                                        {{BQSD}}
                                    </p>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="24">
                                    <p>
                                        <span style="width:18%">最低还款额未还金额:</span>
                                        {{WHJE}}
                                    </p>
                                </el-col>
                            </el-row>
                        </div>
                    </div>
                    <div class="box-group businessIndex">
                        <div class="content">
                            <el-row>
                                <el-col :span="8">
                                    <p>
                                        <span>当前逾期金额:</span>
                                        {{arrearsQuery3001Form.AGEAMT}}
                                    </p>
                                </el-col>
                                <el-col :span="8">
                                    <p>
                                        <span>当前连续逾期次数:</span>
                                        {{arrearsQuery3001Form.AGEDAYS}}
                                    </p>
                                    <p></p>
                                </el-col>
                                <el-col :span="8">
                                    <p>
                                        <span>近24期累计逾期次数:</span>
                                        {{oduetimes}}
                                    </p>
                                    <p></p>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="24">
                                    <p>
                                        <span style="width:18%">近24期逾期情况:</span>
                                        {{paybillhistory}}
                                    </p>
                                </el-col>
                            </el-row>
                        </div>
                    </div>
                    <div class="box-group businessIndex">
                        <div class="content">
                            <el-row>
                                <el-col :span="8">
                                    <p>
                                        <span>信用额度:</span>
                                        {{arrearsQuery3001Form.CREDITLIMIT}}
                                    </p>
                                    <p>
                                        <span>临时额度生效日期:</span>
                                        {{arrearsQuery3001Form.TLMTBEG | formatDate}}
                                    </p>
                                    <p>
                                        <span>预借现金信用额度:</span>
                                        {{arrearsQuery3001Form.CALIMIT}}
                                    </p>
                                    <p>
                                        <span>按日分期额度:</span>
                                        {{arrearsQuery3001Form.LMPLIMIT}}
                                    </p>
                                </el-col>
                                <el-col :span="8">
                                    <p>
                                        <span>可用额度:</span>
                                        {{arrearsQuery3001Form.AVLIMT}}
                                    </p>
                                    <p>
                                        <span>临时额度失效日期:</span>
                                        {{arrearsQuery3001Form.TLMTEND | formatDate}}
                                    </p>
                                    <p>
                                        <span>预借现金可用额度:</span>
                                        {{arrearsQuery3001Form.CALIMITAVB}}
                                    </p>
                                    <p>
                                        <span>按日分期可用额度:</span>
                                        {{arrearsQuery3001Form.DAILYAVAIL}}
                                    </p>
                                </el-col>
                                <el-col :span="8">
                                    <p>
                                        <span>临时额度:</span>
                                        {{arrearsQuery3001Form.TEMPLIMIT}}
                                    </p>
                                    <p>
                                        <span></span>
                                    </p>
                                    <p>
                                        <span></span>
                                    </p>
                                    <p>
                                        <span>按日分期额度到期日:</span>
                                        {{arrearsQuery3001Form.LOANDAY|formatDate}}
                                    </p>
                                </el-col>
                            </el-row>
                        </div>
                    </div>
                    <div class="box-group businessIndex">
                        <div class="content">
                            <el-row>
                                <el-col :span="8">
                                    <p>
                                        <span>自扣还款方式:</span>
                                        {{AutoRepayAcct_4017.REPAYCODE | filterREP(REPAYCODE_DICT)}}
                                    </p>
                                </el-col>
                                <el-col :span="8">
                                    <p>
                                        <span style="width:50%;">自扣还款账号:</span>
                                        {{AutoRepayAcct_4017.ACCT}}
                                    </p>
                                </el-col>
                                <el-col :span="8">
                                    <p>
                                        <span>自扣还款状态:</span>
                                        {{AutoRepayAcct_4017.STATUS | filterAUTOPAYSTATUS(AutoRepayAcct_4017.ACCT)}}
                                    </p>
                                </el-col>
                            </el-row>
                        </div>
                    </div>
                    <!-- 话术 -->
                    <div class="hstable_wrap" v-if="speechList.length!=0">
                        <el-table
                            :data="speechList"
                            border
                            stripe
                            header-row-class-name="headerRow"
                            ref="showListTable"
                            class="heard-bg business_table hstable"
                            @selection-change="handleSelectionChange"
                        >
                            <el-table-column type="selection" label=" " min-width="55"></el-table-column>
                            <el-table-column label="业务话术">
                                <template slot-scope="scope">{{scope.row.content}}</template>
                            </el-table-column>
                        </el-table>
                    </div>
                </div>
            </template>
        </cardComponent>
    </div>
</template>

<script>
// 导入混入其他银行特殊业务， 导入名字最好固定
// 导入默认公用模块，是否展示字段存在Defaultxxxx文件中，其他银行是否需要展示, 在自己的逻辑页面修改对应字段的boole值，只能在本银行修改
import { mapState } from 'vuex';
import moment from 'moment';
import cardComponent from '@/components/cardComponent/cardComponent.vue';
import { getDictSelectList, getAccountTypeName, getNewCUPAYM24 } from '@/utils/Common';
import { getToken, getTokenHsbankNo } from '@/utils/auth';
export default {
    name: 'ArrearsQuery',
    // 混入的调用 ， 如同名后面的会覆盖前面的混入
    components: {
        cardComponent,
    },
    data() {
        return {
            pageLoading: false,
            bnknbr: getTokenHsbankNo('HsbankNo'),
            BQSD: '',
            WHJE: '',
            arrearsQuery3001Form: {
                RETCODE: '000000',
                BALNCE: '',
                BALNCEX: '',
                PYMTCLUD: '',
                PYMTCLUDX: '',
                CASHAVAL: '',
                LASTPAYDAY: '',
                LASTPAYAMT: '',
                CASHADVX: '',
                AGEAMT: '',
                AGEAMTX: '',
                AGEDAYS: '',
                AGEDAYSX: '',
                CREDITLIMIT: '',
                XCREDLIMIT: '',
                AVLIMT: '',
                XAVLIMT: '',
                TEMPLIMIT: '',
                TLMTBEG: '',
                TLMTEND: '',
                CALIMIT: '',
                CALIMITAVB: '',
                CASHAVALX: '',
                LMPLIMIT: '',
                LMPAVAIL: '',
                SIGN: '',
                PURCRED: '',
                CASHADV: '',
                ADVFEE: '',
                ADVFEEX: '',
                REPAYCODE: '',
                BANKACCT: '',
                INTCHG: '',
                PENCHG: '',
                MPREMBAL: '',
                MPREMINTFEE: '',
                BALNCEFLG: '',
                BALNCEFLGX: '',
                STMTDTE: '',
                AMOUNT: '',
                PURCHAMT: '',
                CASHAD: '',
                DUEDATE: '',
                MINPAY: '',
                CASHADFEE: '',
            },
            arrearsQuery3005Form: {
                RETCODE: '000000',
                AMOUNT: '',
                PURCHAMT: '',
                CASHAD: '',
                DUEDATE: '',
                MINPAY: '',
                CASHADFEE: '',
                INTCHG: '',
            },
            pageLoading: true,
            arrearsQuery3054Form: {},
            refamtpay: '',

            REPAYCODE_DICT: [],


            pagingDataList: [], // 翻页上送字段列表
            currentPageIndex: 0, // 当前页下一页’  按钮的显示控制阀
            nextButtonFlag: false, // 下翻页按钮 显示控制阀
            tableData: [],

            mptypeList: [],
            mpstatusList: [],
            totalSumMap: {
                currentTotalBalance: 0,
                currentMonthTotalPayBack: 0,
                lastTotalPayBack: 0,
            },
            currentData: {}, // 当前分页标识数据
            searchForm: { // 搜索表单字段
                accttype: '',
                cardno: '',
            },
            cardList: [],

            NEXTDAY_3077: '',//翻页交易日期
            NEXTMPNO_3077: '',//翻页分期付款序号
            RtnindFlag3077: '',//翻页标志
            tableData3077: [],//3077转账分期未还列表
            resultlist3077: [],
            unpaympamttotal3077: '0.0',//未摊销转账分期总额

            NEXTDAY_3121: '',//翻页交易日期
            NEXTMPNO_3121: '',//翻页分期付款序号
            RtnindFlag3121: '',//翻页标志
            tableData3121: [],//3077转账分期未还列表
            resultlist3121: [],
            unpaympamttotal3121: '0.0',//未摊销转账分期总额

            paybillhistory: '',//近24期还款情况
            oduetimes: '0',//近24期累计逾期次数
            stmtamt: '0',//账单分期未请款金额
            speechList: [],//话术列表
            selectedList: [],
            MenuId: '',
        };
    },
    filters: {
        // 日期格式转换
        formatDate(val) {

            val = (`${val}`).trim();
            console.log("***************************", val);
            if (val === 0 || val === '0') {
                return '';
            }
            if (val === '99999999') {
                return '见单即付';
            }
            if (val === '00000000') return val;
            if (val) {
                return moment(val, 'YYYYMMDD').format('YYYY-MM-DD');
            }
            return '';

        },
        filterREP(val, REPAYCODE_DICT) {
            let newVal = (`${val}`).trim();
            if (newVal === '' || newVal === 'undefined') {
                return '';
            }
            REPAYCODE_DICT.forEach((item) => {
                if (newVal === item.code) {
                    newVal = item.label;
                }
            });
            return newVal;
        },

        filterSTATUS: (value, mpstatusList) => {
            value = (`${value}`).trim();
            for (let index = 0; index < mpstatusList.length; index++) {
                const element = mpstatusList[index];
                if (element.code === value) {
                    return element.label;
                }
            }
        },
        filterMPTYPE: (value, mptypeList) => {
            value = (`${value}`).trim();
            for (let index = 0; index < mptypeList.length; index++) {
                const element = mptypeList[index];
                if (element.code === value) {
                    return element.label;
                }
            }
        },
        filterAUTOPAYSTATUS: (value, acct) => {
            value = (`${value}`).trim();
            acct = (`${acct}`).trim();
            if (acct === '' || acct === 'undefined' || value === '' || value === 'undefined') {
                return '';
            } else {
                switch (value) {
                    case '00':
                        return '委托关系成功';
                        break;
                    case 'AA':
                        return '关系待验证';
                        break;
                    default:
                        return '失败';
                        break;
                }
            }
        },
    },

    async mounted() {
        this.MenuId = this.$route.params.id || '';
        //this.accountType = await getAccountTypeName(this.cardList_3601, this.cardInfo_3004, this)
        this.mptypeList = await getDictSelectList('MP_TYPE', this);
        this.mpstatusList = await getDictSelectList('MP_STATUS', this);
        this.REPAYCODE_DICT = await getDictSelectList('REPAYCODE', this);
        this.init();
        this.changeCardList(this.cardInfo_3004.CATEGORY + '');
        await this.getspeechList();
    },

    computed: mapState({
        cardInfo_3004: state => state.common.cardInfo_3004, // 默认卡信息
        defaultParams: state => state.common.defaultParams, // 接口默认参数
        pinFlag: state => state.common.pinFlag, // 是否密码检查标志
        AccountionTYPE_INFO: state => state.common.AccountionTYPE_INFO, //账户类别列表
        cardList_3601: state => state.common.cardList_3601, //卡列表
        isCurrentMenuInfo: state => state.menu.isCurrentMenuInfo,
        // AutoRepayAcct_4017: state => state.common.AutoRepayAcct_4017,

    }),
    methods: {

        init() {
            console.log("默认账户类别：" + this.cardInfo_3004.CATEGORY);
            console.log("默认账户：" + this.cardInfo_3004.CARDNO);
            this.searchForm.accttype = this.cardInfo_3004.CATEGORY + '';
            this.searchForm.cardno = this.cardInfo_3004.CARDNO;
        },
        changeCardList(val) {
            console.log("当前账户类型：" + val);
            let hasDefault = false; //是否包含默认卡
            this.cardList = [];

            this.cardList_3601.forEach((item) => {
                if (item.CATEGORY + '' === val) {
                    this.cardList.push(item);
                    if (item.CARDNBR === this.cardInfo_3004.CARDNO) {
                        hasDefault = true;
                    }
                }
            });

            //包含默认卡，卡号显示默认卡，不包含，显示cardList里第一张卡号
            if (hasDefault) {
                this.searchForm.cardno = this.cardInfo_3004.CARDNO;
            } else {
                this.searchForm.cardno = this.cardList[0].CARDNBR;
            }
            // 账户资料查询，调用3001
            this.getData();



        },
        //根据菜单id查询话术列表
        async getspeechList() {
            console.log("this.isCurrentMenuInfo.id", this.isCurrentMenuInfo.id);
            var checkParam = {
                'id': this.MenuId || this.isCurrentMenuInfo.id,
            };
            this.$post.busiMenu.getlistByMenuId(checkParam).then((res) => {
                console.log("话术查询结果：", res);
                if (res.status === 200) { // http通讯成功
                    if (res.data.status == 0) { // 业务请求成功
                        this.speechList = res.data.content;
                    }
                }
            });
        },
        handleSelectionChange(val) {
            this.selectedList = val;
        },
        changeCard(val) {
            console.log("当前卡号：" + val);

            this.searchForm.cardno = val;

            // 账户资料查询，调用3001
            //this.getData();

        },
        calTotalSum() {

            // 当日账面总余额 当月还款总金额 最近一次还款金额

            this.multiAccounts.forEach(item => {

                this.getAccountSum(item.CARDNBR);
            });

        },

        getAccountSum(cardNo) {
            // 设置请求参数 -- 3001 交易
            const appBody = {
                CARDNO: cardNo, // 卡号
                PINFLAG: this.defaultpinFlag, // 是否检查密码标志 0-不检查
            };
            const params = JSON.parse(JSON.stringify(this.defaultParams));
            params.body.appHead.tranCode = '3001';
            params.body.appBody = appBody;
            // 跑 3001 交易
            this.$post.common.transPort(params).then((res) => {
                if (res.status === 200) {
                    const result = JSON.parse(res.data.jsonRes);
                    if (result.sysHead.rspCd === '000000') {
                        console.log("this.totalSumMap.currentTotalBalance", this.totalSumMap.currentTotalBalance);
                        this.totalSumMap.currentTotalBalance = parseFloat(this.totalSumMap.currentTotalBalance) + parseFloat(result.body.appBody.BALNCE);
                        this.totalSumMap.currentMonthTotalPayBack = parseFloat(this.totalSumMap.currentMonthTotalPayBack) + parseFloat(result.body.appBody.PYMTCLUD);
                        this.totalSumMap.lastTotalPayBack = parseFloat(this.totalSumMap.lastTotalPayBack) + parseFloat(result.body.appBody.LASTPAYAMT);
                        this.$store.commit('common/UPDATE_CARD_ACCOUNT_INFO', result.body.appBody);
                    } else {
                        //this.$message.error(result.sysHead.rspMsg);
                    }
                } else {
                    //this.$message.error('请求失败');
                }

            });
        },

        async getData() {
            this.pageLoading = true;

            // 3005查询当期账单信息
            await this.get3005();
            //3046查询账单分期未请款金额
            await this.get3046();
            // 3001查询账户信息
            await this.get3001();
            //3054查询信用历史
            await this.get3054();
            if (this.arrearsQuery3054Form) {

                this.paybillhistory = await getNewCUPAYM24(this.arrearsQuery3054Form.CUPAYM24);
                this.oduetimes = countNum(this.paybillhistory);

            }





            function countNum(str) {
                var sum = 0;
                var arr = str.split("");
                for (var i in arr) {
                    var a = Number(arr[i]);
                    if (a > 0 && a <= 9) {
                        sum++;
                    }
                }
                return sum;
            }
            /**
             * 3077查询所有未还款转账分期交易，计算未摊销本金和手续费总额
             */
            console.log('3077交易进入');
            await this.get3077('first').then(() => {
                console.log('3077成功后执行方法');
                console.log("this.tableData3077_2", this.tableData3077);
                this.tableData3077.forEach((item, index) => { // 判断此次查询数据最后一条记翻页分期付款序号是否在已有列表中
                    let unpaybj = item.REMPBAL;//未摊销本金
                    let unpayfee = item.REMFEE;//剩余手续费
                    if (item.MPTYPE === 'W') {
                        this.unpaympamttotal3121 = parseFloat(this.unpaympamttotal3121) + parseFloat(unpaybj);
                    } else {
                        this.unpaympamttotal3077 = parseFloat(this.unpaympamttotal3077) + parseFloat(unpaybj) + parseFloat(unpayfee);
                    }
                    //this.unpaympamttotal3077 = parseFloat(this.unpaympamttotal3077) + parseFloat(unpaymp);
                    //console.log('unpaybj:' + unpaybj + ',unpayfee:' + unpayfee + ',unpaymp:' + unpaymp + ',unpaympamttotal3077:' + this.unpaympamttotal3077);
                });
                this.unpaympamttotal3077 = parseFloat(this.unpaympamttotal3077).toFixed(2);
                this.unpaympamttotal3121 = parseFloat(this.unpaympamttotal3121).toFixed(2);
                console.log('unpaympamttotal3077:' + this.unpaympamttotal3077 + ',unpaympamttotal3121:' + this.unpaympamttotal3121);
            });


            /**
             * 3121查询所有未还款按日分期交易，计算未摊销本金总额
             */

            // console.log('3077交易');
            //await this.get3121('first');
            // console.log("this.tableData3121", this.tableData3121);
            // this.tableData3121.forEach((item, index) => { // 判断此次查询数据最后一条记翻页分期付款序号是否在已有列表中
            //     let unpaybj = item.REMPPL;//未摊销本金
            //     this.unpaympamttotal3121 = parseFloat(this.unpaympamttotal3121) + parseFloat(unpaybj);
            //     //console.log('unpaybj:' + unpaybj + ',unpaympamttotal3121:' + this.unpaympamttotal3121);
            // });
            // this.unpaympamttotal3121 = parseFloat(this.unpaympamttotal3121).toFixed(2);

            this.pageLoading = false;
        },
        // 3005
        async get3005() {
            console.log('3005交易');
            this.defaultParams.sysHead.busiName = '欠款查询';
            // 3005 配置请求头
            const appBody_3005 = {
                CARDNBR: this.searchForm.cardno, // 卡号,
                TRANYM: 0,
                OPTION: 'L',
                PINFLAG: this.defaultpinFlag,
            };
            const defaultParams_3005 = JSON.parse(JSON.stringify(this.defaultParams));
            defaultParams_3005.body.appHead.tranCode = '3005';
            defaultParams_3005.body.appBody = appBody_3005;
            await this.$post.common.transPort(defaultParams_3005).then((res) => {
                if (res.status === 200) {
                    const result = JSON.parse(res.data.jsonRes);
                    if (result.sysHead.rspCd === '000000') {
                        this.arrearsQuery3005Form = { ...result.body.appBody };
                        console.log(this.arrearsQuery3005Form);
                    }
                }
            });
        },
        // 3046
        async get3046() {
            console.log('3046交易');
            this.defaultParams.sysHead.busiName = '欠款查询';
            // 3005 配置请求头
            const appBody_3046 = {
                OPT: 1, // 查询方式 1-用卡号查询 2-用证件号码查询
                CARDNBR: this.searchForm.cardno, // 卡号
                MPTYPE: 'Y', // 分期类型,y-账单分期
                STATUS: '30', // 分期申请状态,30-待请款
                PINFLAG: '0', // 是否检查密码标志 0-不检查
                RTNIND: '', // 翻页标志 首次传空， 翻页传1
                APPREF: '', // 分期申请编号，首次查询时送空， 下翻页查询时上送上次查询结果的最后一条记录返回的分期付款申请编号
            };
            const defaultParams_3046 = JSON.parse(JSON.stringify(this.defaultParams));
            defaultParams_3046.body.appHead.tranCode = '3046';
            defaultParams_3046.body.appBody = appBody_3046;
            await this.$post.common.transPort(defaultParams_3046).then((res) => {
                if (res.status === 200) {
                    const result = JSON.parse(res.data.jsonRes);
                    console.log("this.result3046:", result);
                    if (result.sysHead.rspCd === '000000') {
                        if (result.body.appBody.dataList.length > 0) {
                            this.stmtamt = result.body.appBody.dataList[0].MPAMT;
                        } else {
                            this.stmtamt = '0';
                        }
                    } else {
                        this.stmtamt = '0';
                    }
                }
            });
        },
        async get3001() {
            console.log('3001交易');
            // 3001 配置请求头
            const appBody_3001 = {
                CARDNO: this.searchForm.cardno || '',
                PINFLAG: this.defaultpinFlag,
            };
            const defaultParams_3001 = JSON.parse(JSON.stringify(this.defaultParams));
            defaultParams_3001.body.appHead.tranCode = '3001';
            defaultParams_3001.body.appBody = appBody_3001;
            await this.$post.common.transPort(defaultParams_3001).then((res) => {
                if (res.status === 200) {
                    const result = JSON.parse(res.data.jsonRes);
                    if (result.sysHead.rspCd === '000000') {
                        this.$store.commit('common/UPDATE_CARD_ACCOUNT_INFO', result.body.appBody);
                        this.arrearsQuery3001Form = { ...result.body.appBody };
                        console.log(this.arrearsQuery3001Form);

                        function ForDight(Dight, How) {
                            var Dight = Math.round(Dight * Math.pow(10, How)) / Math.pow(10, How);
                            return Dight;
                        }
                        // 本期时点欠款余额 = 带符号本币账单金额（69、70域） - 已结算付款额（81域） + 带符号本币贷记调整金额（117、118域）
                        let close_cha = this.arrearsQuery3001Form.CLOSECHA; // 本币账单余额方向 3001-70
                        let close_bal = this.arrearsQuery3001Form.CLOSEBAL; // 本币账单余额 3001-69
                        const pymt_clud = this.arrearsQuery3001Form.PYMTCLUD; // 已结算付款额 3001-81
                        const cradj_s = this.arrearsQuery3001Form.CRADJS; // 本币贷记调整金额符号  3001-118
                        const cred_adj = this.arrearsQuery3001Form.CREDADJ; // 本币贷记调整金额 3001-117

                        if (close_cha === null || close_cha === '') {
                            close_cha = '+';
                        }
                        if (close_bal === null || close_bal === '') {
                            close_bal = '0.0';
                        }
                        if (pymt_clud === null || pymt_clud === '') {
                            close_cha = '0.0';
                        }
                        if (cradj_s === null || cradj_s === '') {
                            close_bal = '+';
                        }
                        if (cred_adj === null || cred_adj === '') {
                            close_cha = '0.0';
                        }

                        var t_c = '';

                        if (close_cha === '-') {
                            t_c = `(${parseFloat(close_cha + close_bal)})`;
                        } else {
                            t_c = parseFloat(close_bal);
                        }
                        if (pymt_clud < 0) {
                            t_c = `${t_c} - (${parseFloat(pymt_clud)})`;
                        } else {
                            t_c = `${t_c} - ${parseFloat(pymt_clud)}`;
                        }
                        if (cradj_s === '-') {
                            t_c = `${t_c} + (${parseFloat(cradj_s + cred_adj)})`;
                        } else {
                            t_c = `${t_c} + ${parseFloat(cred_adj)}`;
                        }

                        t_c = `${t_c} - ${parseFloat(this.stmtamt)}`;
                        // 本期时点欠款金额
                        const bq = parseFloat(close_cha + close_bal) - parseFloat(pymt_clud) + parseFloat(cradj_s + cred_adj) - parseFloat(this.stmtamt);
                        const txt = `本币账单金额 - 已结算付款额  + 本币贷记调整金额 - 账单分期待请款金额 = ${t_c} = ${ForDight(bq, 2)}`;
                        this.BQSD = txt;

                        // 最低还款额 - 已结算付款额（81域） + 带符号本币贷记调整金额（117、118域）。如果小于0，则无最低还款额未还部分。
                        let minpay = this.arrearsQuery3001Form ? this.arrearsQuery3001Form.STMMINDUE : ''; // 最小还款额 3001-166
                        let wh = parseFloat(minpay) - parseFloat(pymt_clud) + parseFloat(cradj_s + cred_adj) - parseFloat(this.stmtamt);
                        let WHJEtxt = '';

                        let tc = '';
                        tc = parseFloat(minpay);

                        if (pymt_clud < 0) {
                            tc = `${tc} - (${parseFloat(pymt_clud)})`;
                        } else {
                            tc = `${tc} - ${parseFloat(pymt_clud)}`;
                        }
                        if (cradj_s === '-') {
                            tc = `${tc} + (${parseFloat(cradj_s + cred_adj)})`;
                        } else {
                            tc = `${tc} + ${parseFloat(cred_adj)}`;
                        }
                        tc = `${tc} - ${parseFloat(this.stmtamt)}`;
                        WHJEtxt = `最低还款额 - 已结算付款额  + 本币贷记调整金额 - 账单分期待请款金额 = ${tc} = ${ForDight(wh, 2)}`;

                        this.WHJE = WHJEtxt;

                        let balnce = this.arrearsQuery3001Form.BALNCE; // 人民币账面余额
                        const balnceflg = this.arrearsQuery3001Form.BALNCEFLG; // 人民币账面余额方向
                        const mp_rem_bal = this.arrearsQuery3001Form.MPREMBAL; // 分期付款剩余待摊销本金
                        const mp_rem_intfee = this.arrearsQuery3001Form.MPREMINTFEE; // 分期付款剩余待摊销手续费
                        const penchg = this.arrearsQuery3001Form.PENCHG; // 本币应收未收违约金
                        if (balnceflg === '-') {
                            balnce *= (-1);
                        }
                        this.refamtpay = parseFloat(balnce) + parseFloat(mp_rem_bal) + parseFloat(mp_rem_intfee) + parseFloat(penchg);
                        this.refamtpay = this.refamtpay.toFixed(2);
                    }
                }
            });
        },
        // 3054
        async get3054() {
            this.arrearsQuery3054Form = {};//先清空缓存
            console.log('3054交易');
            // 3054 配置请求头
            const appBody_3054 = {
                CARDNBR: this.searchForm.cardno, // 卡号,
                QUERY: 0,
                OPTION: 'L',
                PINFLAG: '0',
            };
            const defaultParams_3054 = JSON.parse(JSON.stringify(this.defaultParams));
            defaultParams_3054.body.appHead.tranCode = '3054';
            defaultParams_3054.body.appBody = appBody_3054;
            await this.$post.common.transPort(defaultParams_3054).then((res) => {
                if (res.status === 200) {
                    const result = JSON.parse(res.data.jsonRes);
                    if (result.sysHead.rspCd === '000000') {
                        this.arrearsQuery3054Form = result.body.appBody;
                        console.log("this.arrearsQuery3054Form", this.arrearsQuery3054Form);
                    }
                }
            });
        },



        // 3077分期付款交易明细查询
        async get3077(type) {
            if (type === 'first') {
                this.RtnindFlag3077 = '';
                this.NEXTDAY_3077 = '20000101';
                this.NEXTMPNO_3077 = '';
                this.resultlist3077 = [];
            }
            const appBody = {
                CARDNBR: this.searchForm.cardno, // 卡号
                // 空或Z：全部  A：灵活分期 C：信用计划分期 B：余额转移 H：银联POS分期 L：大额分期 M：邮购分期  P：自行POS分期 S：深圳银联POS分期 Y：余额/账单分期 D：自动分期
                MPTYPE: '', // 分期付款类型
                OPERCODE: 1, // 操作代码  0全部返回  1可提前还款的分期交易    2可撤销的分期交易
                OPT: '1', // 查询方式 1-用卡号查询 2-用证件号码查询
                //CATE: this.accountType, // 账户类别 查询方式为2时，必填
                PINFLAG: this.pinFlag, // 是否检查密码标志
                BEGDAY: "20000101", // 起始日期
                ENDDAY: moment(new Date()).format('YYYYMMDD'), // 结束日期 两个月 内的
                RTNIND: this.RtnindFlag3077,// 翻页标志 首次传空， 翻页传1
                NEXTDAY: this.NEXTDAY_3077,// 首次查询时送查询起始日期， 下翻页查询时上送上次查询结果的最后一条记录返回的分期付款交易日期
                NEXTMPNO: this.NEXTMPNO_3077,// 首次查询时送起始序号，默认为0 下翻页查询时上送上次查询结果的最后一条记录返回的交易序号
            };
            const defaultParams = JSON.parse(JSON.stringify(this.defaultParams));
            defaultParams.body.appHead.tranCode = '3077';
            defaultParams.body.appBody = appBody;
            // 3077交易

            await this.$post.common.transPort(defaultParams).then(async (res) => {
                if (res.status === 200) {
                    const result = JSON.parse(res.data.jsonRes);
                    if (result.sysHead.rspCd === '000000') {
                        this.resultlist3077.push(...result.body.appBody.dataList);

                        if (result.body.appBody.RTNIND === '1') {
                            this.NEXTDAY_3077 = result.body.appBody.dataList[result.body.appBody.dataList.length - 1].BEGYM;
                            this.NEXTMPNO_3077 = result.body.appBody.dataList[result.body.appBody.dataList.length - 1].MPNO;
                            // 修改翻页标志 
                            this.RtnindFlag3077 = result.body.appBody.RTNIND
                            await this.get3077();

                        } else {
                            console.log(' this.resultlist3077——数据接收到了', this.resultlist3077);
                            //this.tableData3077 = await this.resultlist3077.filter((item) => item.MPTYPE != 'W');
                            this.tableData3077 = this.resultlist3077;
                            console.log("this.tableData3077_1", this.tableData3077);
                        }
                    } else {

                    }
                } else {
                    this.pageLoading = false;
                }
            });
        },
        // 3121分期付款交易明细查询
        async get3121(type) {

            if (type === 'first') {
                this.RtnindFlag3121 = '';
                this.NEXTDAY_3121 = '20000101';
                this.NEXTMPNO_3121 = '';
                this.resultlist3121 = [];

            }
            const appBody = {
                CARDNBR: this.searchForm.cardno, // 卡号
                // 空或Z：全部  A：灵活分期 C：信用计划分期 B：余额转移 H：银联POS分期 L：大额分期 M：邮购分期  P：自行POS分期 S：深圳银联POS分期 Y：余额/账单分期 D：自动分期
                MPTYPE: '', // 分期付款类型
                OPERCODE: 1, // 操作代码  0全部返回  1可提前还款的分期交易    2可撤销的分期交易
                OPT: '1', // 查询方式 1-用卡号查询 2-用证件号码查询
                //CATE: this.accountType, // 账户类别 查询方式为2时，必填
                PINFLAG: this.pinFlag, // 是否检查密码标志
                BEGDAY: "20000101", // 起始日期
                ENDDAY: moment(new Date()).format('YYYYMMDD'), // 结束日期 两个月 内的
                RTNIND: this.RtnindFlag3121,// 翻页标志 首次传空， 翻页传1
                NEXTDAY: this.NEXTDAY_3121,// 首次查询时送查询起始日期， 下翻页查询时上送上次查询结果的最后一条记录返回的分期付款交易日期
                NEXTMPNO: this.NEXTMPNO_3121,// 首次查询时送起始序号，默认为0 下翻页查询时上送上次查询结果的最后一条记录返回的交易序号
            };
            const defaultParams = JSON.parse(JSON.stringify(this.defaultParams));
            defaultParams.body.appHead.tranCode = '3121';
            defaultParams.body.appBody = appBody;
            // 3077交易

            await this.$post.common.transPort(defaultParams).then((res) => {
                if (res.status === 200) {
                    const result = JSON.parse(res.data.jsonRes);
                    if (result.sysHead.rspCd === '000000') {
                        this.resultlist3121.push(...result.body.appBody.dataList);

                        if (result.body.appBody.RTNIND === '1') {
                            this.NEXTDAY_3121 = result.body.appBody.dataList[result.body.appBody.dataList.length - 1].BEGYM;
                            this.NEXTMPNO_3121 = result.body.appBody.dataList[result.body.appBody.dataList.length - 1].MPNO;
                            // 修改翻页标志 
                            this.RtnindFlag3121 = result.body.appBody.RTNIND
                            this.get3121();
                        } else {
                            this.pageLoading = false;
                            this.tableData3121 = this.resultlist3121;
                        }
                    } else {
                        this.pageLoading = false;
                    }
                } else {
                    this.pageLoading = false;
                }
            });
        },

        dialogTable() {
            // 设置请求参数
            let NEXTDAY = moment(new Date()).format('YYYYMMDD');
            let NEXTMPNO = 0;
            if (this.pagingDataList.length) { // 判断翻页上传字段取值
                NEXTDAY = this.pagingDataList[this.currentPageIndex].NEXTDAY;
                NEXTMPNO = this.pagingDataList[this.currentPageIndex].NEXTMPNO;
            }



            const appBody = {
                CARDNBR: this.cardInfo_3004.CARDNO || '', // 卡号
                // 空或Z：全部  A：灵活分期 C：信用计划分期 B：余额转移 H：银联POS分期 L：大额分期 M：邮购分期  P：自行POS分期 S：深圳银联POS分期 Y：余额/账单分期 D：自动分期
                MPTYPE: '', // 分期付款类型
                OPERCODE: 0, // 操作代码  0全部返回  1可提前还款的分期交易    2可撤销的分期交易
                OPT: 1, // 查询方式 1-用卡号查询 2-用证件号码查询
                CUSTNBR: '', // 证件号码 查询方式为2时，必填
                KEYTYPE: '', // 证件类型 查询方式为2时，必填 以银行在CODES/ETHNC中参数定义为准
                //CATE: this.accountType, // 账户类别 查询方式为2时，必填
                PINFLAG: this.defaultpinFlag, // 是否检查密码标志
                BEGDAY: moment(new Date()).subtract(12, 'months').format('YYYYMMDD'), // 起始日期
                ENDDAY: moment(new Date()).format('YYYYMMDD'), // 结束日期 两个月 内的
                RTNIND: this.pagingDataList.length === 0 ? '' : 1, // 翻页标志 首次传空， 翻页传1
                NEXTDAY, // 首次查询时送查询起始日期， 下翻页查询时上送上次查询结果的最后一条记录返回的分期付款交易日期
                NEXTMPNO, // 首次查询时送起始序号，默认为0 下翻页查询时上送上次查询结果的最后一条记录返回的交易序号
            };
            const defaultParams = JSON.parse(JSON.stringify(this.defaultParams));
            defaultParams.body.appHead.tranCode = '3077';
            defaultParams.body.appBody = appBody;
            // 3077交易
            this.$post.common.transPort(defaultParams).then((res) => {
                this.nextButtonFlag = false;
                if (res.status === 200) {
                    const result = JSON.parse(res.data.jsonRes);
                    if (result.sysHead.rspCd === '000000') {
                        this.tableData = result.body.appBody.dataList || [];

                        // 先通过返回来的 翻页标志 RTN-IND的值判断   0：查询完毕；1：需继续翻页查询；
                        if (result.body.appBody.RTNIND = '1') {
                            this.nextButtonFlag = true;
                            this.RTNIND_flag = '1';

                            this.currentData = {
                                NEXTDAY: result.body.appBody.dataList[result.body.appBody.dataList.length - 1].NEXTDAY,
                                NEXTMPNO: result.body.appBody.dataList[result.body.appBody.dataList.length - 1].NEXTMPNO,
                            };

                        } else {
                            this.nextButtonFlag = false;
                        }

                        this.nextButtonFlag = !(result.body.appBody.dataList.length < 5);


                        let flag = false;
                        let currentIndex;
                        this.pagingDataList.forEach((item, index) => { // 判断此次查询数据最后一条记翻页分期付款序号是否在已有列表中
                            if (item.NEXTMPNO === this.currentData.NEXTMPNO) {
                                flag = true;
                                currentIndex = index;
                            }
                        });
                        if (flag) { // 存在
                            this.currentPageIndex = currentIndex;
                        } else {
                            this.pagingDataList.push(this.currentData);
                            this.currentPageIndex = this.pagingDataList.length - 1;
                        }
                    } else {
                        //this.$message.error(result.sysHead.rpsMs);
                    }
                } else {
                    //this.$message.error('网络请求失败!');
                }
            });
        },
        // 上下页切换
        handleChangePage(type) {
            if (type === 'pre') { // 切换到上一页
                if (this.currentPageIndex - 2 < 0) {
                    this.pagingDataList = []; // 清空缓存 申请编号 -> 相当于首次查询
                } else {
                    this.currentPageIndex = this.currentPageIndex - 2;
                }
                this.dialogTable();
            } else { // 切换到下一页
                this.dialogTable();
            }
        },
    },
};
</script>

<style lang='scss'>
#arrearsQueryBox .myCardComponent {
}
.arrearsQueryMain {
    .businessIndex {
        padding: 6px 8px !important;
    }
}
#arrearsQueryBox {
    width: 98%;
    background: #fff;
    box-sizing: border-box;
    border-radius: 5px;
    .el-card__body {
        padding: 0 !important;
    }
    /* //头部内容 */
    .tab-header {
        width: 100%;
        text-align: left;
        span {
            font-size: 14px;
        }

        .headerTitle {
            font-size: 16px;
            margin: 10px 0px;
            color: skyblue;
        }
    }
    //主体内容
    .arrearsQueryMain {
        /* margin: 0px 30px 20px 10px; */
        color: #111;
        .content {
            width: 100%;
        }
        .content_bottom {
            margin-top: 20px;
        }
        .box-group .content p {
            color: #4e4d4d;
            font-size: 14px;
            text-align: left;
            span {
                color: #000;
                text-align: right;
                display: inline-block;
                width: 54%;
                margin-right: 4px;
            }
        }
        .el-form {
            .el-form-item--small.el-form-item {
                margin-bottom: 5px;
            }
        }
        .el-row {
            .el-col {
                text-align: left;
                color: #111;
                span {
                    display: inline-block;
                    /* width: 85%; */
                }
                .queryMainLeft {
                    width: 50%;
                    text-align: right;
                    margin-right: 7px;
                    color: #999;
                }
                .queryMainLeftSpecial {
                    width: 25%;
                    text-align: right;
                    margin-right: 7px;
                    color: #999;
                }
            }
        }
        .tiekuLine {
            width: 80%;
            border-bottom: 1px solid #eee;
            margin: 0 auto 50px;
        }
    }
    .btnBox {
        margin-top: 30px;
        text-align: center;
    }
}
</style>
